#include"data_global.h"
#include "sem.h"
#define DEV_UART 			"/dev/ttyUSB0"
extern prodcons_t init;
void serial_init(int fd)
{
    struct termios options;
    tcgetattr(fd, &options);
    options.c_cflag |= ( CLOCAL | CREAD );
    options.c_cflag &= ~CSIZE;
    options.c_cflag &= ~CRTSCTS;
    options.c_cflag |= CS8;
    options.c_cflag &= ~CSTOPB;
    options.c_iflag |= IGNPAR;
    options.c_iflag &= ~(ICRNL | IXON);
    options.c_oflag = 0;
    options.c_lflag = 0;

    cfsetispeed(&options, B115200);
    cfsetospeed(&options, B115200);
    tcsetattr(fd,TCSANOW,&options);
}

struct env_info b;
void *handler_transfer(void *data)
{
	
	int  dev_uart_fd;
	
    if ((dev_uart_fd = open (DEV_UART, O_RDWR)) < 0)
    {
        perror ("open uart err");
        return NULL;
    }
	
	serial_init (dev_uart_fd);
	
	while(1)
	{
		pthread_mutex_lock(&mutex);
		while(flag != 0)
		{
			pthread_cond_wait(&cond,&mutex);
		}
		read(dev_uart_fd, &b, 24);
		printf("接收线程三轴信息：x:%d ,y:%d , z:%d \n",b.x,b.y,b.z);
		flag = 1;
		pthread_mutex_unlock(&mutex);
		pthread_cond_broadcast(&cond);
	}
	return NULL;
}
